package com.wyp.design.pattern.behavior.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * 实现 Observer 接口中的update方法,
 */
public class Teacher implements Observer {
    private String teacherName;

    public Teacher(String teacherName) {
        this.teacherName = teacherName;
    }


    /**
     * 此方法会在被监听者有改变时调用
     *
     * @param o   被监听者
     * @param arg 改变的事件对象
     */
    @Override
    public void update(Observable o, Object arg) {
        Course course = (Course) o;
        Question question = (Question) arg;
        System.out.println(teacherName + "老师的" + course.getCourseName() + "课程接收到一个" + question.getUserName() + "提交的问答:" + question.getQuestionContent());

    }
}
